 <!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>{$Think.config.site.title} - 供应商管理</title>

    <meta name="keywords" content="{$Think.config.site.keywords}">

    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">

</head>
<style>
#listtable .fa{
	cursor:pointer;
	color:#1ab394;
	margin-right:1em;
}
th .tag{font-size: 12px; color: #e66c6c; font-weight: normal;}
.ibox-title .tag{font-size: 12px; color: #e66c6c; font-weight: normal; display: inline-block; margin-left: 20px;}
.specval-hide{display: none;}
</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
      <div class="row">
            <div class="col-sm-4">
                <div id="nestable-menu">
                	<button type="button" data-action="addnew" class="btn btn-primary btn-sm addsupplier"><i class="fa fa-plus"></i> 新增供应商</button>
                </div>
            </div>
      </div>
      <div class="row">
          <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>供应商列表</h5>
                        <span class="tag"></span>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                        	<div class="col-sm-6">
                        	</div>
                          	<div class="col-sm-6">
                                <div class="input-group pull-right">
                                <form action="{:url('index')}" method="get" enctype="application/x-www-form-urlencoded">
                                <div class="input-group">
                                    <input type="text" placeholder="请输入关键词" class="input-sm form-control" value="{$Think.get.keywords ?? ''}" name="keywords">
                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
                                </div>
                                </form>
                                </div>
                            </div>
                            
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped" id="listtable">
                                <thead>
                                    <tr>
                                        <th width="30"><input name="checkall" id="checkall"  type="checkbox" class="i-checks" value="1"></th>
                                        <th width="200">供应商名<span class="tag">（双击修改）</span></th>
                                        <th width="200">负责人<span class="tag">（双击修改）</span></th>
                                        <th width="200">负责人电话<span class="tag">（双击修改）</span></th>
                                        <th width="200">管理员账号</th>
                                        <th width="200">状态</th>
                                        <th width="">备注</th>
                                        <th width="300">操作</th>
                                    </tr>
                                </thead>
                                <tbody>

                                	{volist name="list" id="vo"}
                                    <tr data-id="{$vo.supplier_id}">
                                        <td>
                                            <input name="ids[]"  type="checkbox" class="i-checks" value="{$vo.supplier_id}">
                                        </td>
                                        <td class="jedit" data-colum="supplier_name">{$vo.supplier_name}</td>
                                        <td class="jedit" data-colum="charge">{$vo.charge}</td>
                                        <td class="jedit" data-colum="charge_phone">{$vo.charge_phone}</td>
                                        <td>{$vo.admin}</td>
                                      	<td>
                                      	{switch name="vo.supplier_status"}
                                            {case value="0"}<button type="button" class="btn btn-default btn-xs btn-status">禁用</button>{/case}
                                            {case value="1"}<button type="button" class="btn btn-primary btn-xs btn-status">启用</button>{/case}
                                        {/switch}
                                        </td>
                                        <td class="jedit" data-colum="remark">{$vo.remark}</td>
                                        <td>
                                            <a href="{:url('suppliergoods/index',['supplierid'=>$vo['supplier_id']])}" class="fa fa-bitcoin""> 商品管理</a>
                                            <i class="fa fa-edit""> 编辑</i>
	                                        <i class="fa fa-trash-o"> 删除</i>
                                        </td>
                                    </tr>
                                   {/volist}

                                </tbody>
                            </table>
                        </div>
                        <div>{$list->render()}</div>
                    </div>
                </div>
            </div>

        </div>
    </div>

    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/peity/jquery.peity.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
    <script src="{$Think.config.site.common_resource_url}js/majax.js"></script>
    <script src="{$Think.config.site.common_resource_url}js/jedit.js"></script>
</body>

</html>
<script>
$('.jedit').jedit({
    class:'inpbox',
    inputclass:'input-sm form-control',
    change:function(n,old){
        var self = this,tr=$(self).closest('tr'),colum=$(self).data('colum'),supplier_id=tr.data('id');
        majax('{:url("quickEdit")}', {supplier_id:supplier_id,colum:colum,value:n},function(d){
            if (d.code>0) {
                $(self).text(n);
            }else{
                $(self).text(old);
            }
        })
    }
});



var layer_font='';
$(document).ready(function() {
	
	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

	//全选
	$("#checkall").bind("ifChecked",function(){
		$("input[name='ids[]']").iCheck("check");
	});
	//取消全选
	$("#checkall").bind("ifUnchecked",function(){
		$("input[name='ids[]']").iCheck("uncheck");
	});

    //新增
    $(".addsupplier").click(function(){
        layer_font = layer.open({
          type: 2,
          title: '新增供应商',
          shadeClose: true,
          shade: 0.8,
          area: ['900px', '70%'],
          content: '<?php echo \think\Request::instance()->root(); ?>/admin/Supplier/add', //iframe的url
        });
    })

    //编辑
    $("#listtable").on("click",".fa-edit",function(){
        var $tr = $(this).closest("tr");
        var supplier_id = $tr.data('id');
        layer_font = layer.open({
          type: 2,
          title: '编辑供应商',
          shadeClose: true,
          shade: 0.8,
          area: ['900px', '70%'],
          content: '<?php echo \think\Request::instance()->root(); ?>/admin/Supplier/edit?supplier_id='+ supplier_id, //iframe的url
        });
    })
	
	//状态
	$("#listtable").on("click",".btn-status",function(){
		var self = this;
		var $tr = $(self).closest("tr");
		var supplier_id = $tr.data("id");
		var status = $(self).hasClass("btn-primary") ? 0 : 1;

        majax('{:url("quickEdit")}', {supplier_id:supplier_id,colum:'supplier_status',value:status},function(d){
            if (d.code>0) {
                if (d.data['supplier_status']>0) {
                    $(self).removeClass("btn-default").addClass("btn-primary").html("启用");
                }else{
                    $(self).removeClass("btn-primary").addClass("btn-default").html("禁用");
                }
            }else{
                layer.msg(d.msg);
            }
        })
	})

    
	//删除按钮注册
	$("#listtable").on("click",".fa-trash-o",function(){
		var $tr = $(this).closest("tr");
		var id = $tr.data("id");
        layer.confirm('删除该供应商？', {
            btn: ['确定删除','不删除'], //按钮
            shade: false //不显示遮罩
        }, function(){
            //确定删除
            majax('{:url("del")}',{ids:id},function(d){
                if (d.code>0) {
                    layer.msg('删除成功', {icon: 1},function(){
                        $tr.remove();
                    });
                    
                }else{
                    layer.msg(d.msg, {icon: 5});
                }
            })
        },
        function(){
            
        });
	});
});	

function editSuccess(d){
    if (d.data=='refresh') {
        location.reload(true);
    }
    layer.close(layer_font);
    layer.msg(d.msg, {icon: 1});
}
</script>